<?php
namespace app\oauth2\controller;
use app\admin\common\Common;
use think\Db;
use app\admin\model\AdminModel;
require_once("QQSDK/qqConnectAPI.php");
class Callback{
    public static function index($type,$state){
        $state = base64_decode($state);
        if ($state =="fore_end_login"){
            //前端登录
            $qc = new \QC();
            $qc-> qq_callback();
            $uuid = $qc->get_unionid();
            //停止session会话
            //session_start();
            $sql = Db::name('admin')->where('qq_unionid',$uuid)->find();
            if (empty($sql)){
                return Common::result(400,'该QQ账号未绑定,请先绑定');
            }
            $data = array(
                "uuid"=>$uuid,
                "username"=>$sql['username'],
                "state"=>$state
            );
            return AdminModel::QQlogin($data);
            //return Common::result(200,"success",$data);
        }elseif($state =="back_end_band"){
            //后台绑定
            $qc = new \QC();
            $qc-> qq_callback();
            $uuid = $qc->get_openid();
            $data = array(
                "uuid"=>$uuid,
                "type"=>$type,
                "status"=>"已绑定"
            );
            return Common::result(200,"success",$data);
        }else{
             return Common::result(500,"type:".$type."<br>state:". $state.'<br>不存在的登录方式或state出现问题，请停止对本站的攻击');
        }
    }
}